package com.hzy.fivepalace.admin.controller;

import com.hzy.fivepalace.admin.annotation.Login;
import com.hzy.fivepalace.admin.controller.base.BaseController;
import com.hzy.fivepalace.admin.service.AdminWxUserService;
import com.hzy.fivepalace.common.util.JacksonUtil;
import com.hzy.fivepalace.common.util.TableDataInfo;
import com.hzy.fivepalace.db.vo.wx.WxWithdrawRecordsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/admin/wxUser")
@Validated
@Api(tags = "用户服务")
@Login
public class AdminWxUserController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(AdminWxUserController.class);

    @Resource
    private AdminWxUserService adminWxUserService;


    /**
     * 审核提现(状态为0调用)
     *
     * @param id
     * @param status
     * @param msg
     * @return
     */
    @PostMapping("/auditWithdraw")
    @ApiOperation(value = "审核提现(状态为0调用)")
    public Object auditWithdraw(@ApiParam(value = "提现记录id") @RequestParam(value = "id") @NotNull Integer id, @ApiParam(value = "状态:2通过,3拒绝") @RequestParam(value = "status") @NotNull Integer status, @ApiParam(value = "状态为3可以传入") @RequestParam(value = "msg") @NotBlank String msg) {

        return adminWxUserService.auditWithdraw(id, status, msg);
    }


    /**
     * 获取提现记录列表
     *
     * @param page
     * @param size
     * @param withdrawRecords
     * @return
     */
    @PostMapping("/getWithdrawRecordsList")
    @ApiOperation(value = "获取提现记录列表")
    public TableDataInfo getWithdrawRecordsList(@ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size, WxWithdrawRecordsVo withdrawRecords) {
        return adminWxUserService.getWithdrawRecordsList(page, size, withdrawRecords);
    }


    /**
     * 获取用户嗨币信息
     *
     * @param userId
     * @return
     */
    @PostMapping("/getUserCommissionInfo")
    @ApiOperation(value = "获取用户嗨币信息")
    public Object getUserCommissionInfo(@ApiParam(value = "用户id", required = true) @RequestParam(value = "userId") @NotNull Integer userId) {

        return adminWxUserService.getUserCommissionInfo(userId);
    }

    /**
     * 绑定推荐人
     * @param userId
     * @param reUserPhone
     * @return
     */
    @PostMapping("/bindReUser")
    @ApiOperation(value = "绑定推荐人")
    public Object bindReUser(@ApiParam(value = "用户id", required = true) @RequestParam(value = "userId") @NotNull Integer userId, @ApiParam(value = "推荐人手机号", required = true) @RequestParam(value = "reUserPhone") @NotBlank String reUserPhone) {

        return adminWxUserService.bindReUser(userId, reUserPhone);
    }

    /**
     * 获取用户团队列表
     *
     * @param page
     * @param size
     * @param userId
     * @return
     */
    @PostMapping("/getUserTeamList")
    @ApiOperation(value = "获取用户团队列表")
    public TableDataInfo getUserTeamList(@ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size, @ApiParam(value = "用户id", required = true) @RequestParam(value = "userId") @NotNull Integer userId) {
        return adminWxUserService.getUserTeamList(page, size, userId);
    }

    /**
     * 获取用户积分明细列表
     *
     * @param page
     * @param size
     * @param userId
     * @return
     */
    @PostMapping("/getUserPointsDetailList")
    @ApiOperation(value = "获取用户积分明细列表")
    public TableDataInfo getUserPointsDetailList(@ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size, @ApiParam(value = "用户id", required = true) @RequestParam(value = "userId") @NotNull Integer userId) {
        return adminWxUserService.getUserPointsDetailList(page, size, userId);
    }


    /**
     * 获取用户嗨币明细列表
     *
     * @param page
     * @param size
     * @param userId
     * @return
     */
    @PostMapping("/getUserCommissionDetailList")
    @ApiOperation(value = "获取用户嗨币明细列表")
    public TableDataInfo getUserCommissionDetailList(@ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size, @ApiParam(value = "用户id", required = true) @RequestParam(value = "userId") @NotNull Integer userId) {
        return adminWxUserService.getUserCommissionDetailList(page, size, userId);
    }

    /**
     * 用户列表
     *
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/getUserList")
    @ApiOperation(value = "用户列表")
    public TableDataInfo getUserList(@ApiParam(value = "状态:为空就查所有,0可用,1禁用,2注销") @RequestParam(value = "status", required = false) Integer status, @ApiParam(value = "用户昵称") @RequestParam(value = "nickname", required = false) String nickname, @ApiParam(value = "手机号码") @RequestParam(value = "phone", required = false) String phone, @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "100") Integer size) {
        return adminWxUserService.getUserList(status, nickname, phone, page, size);
    }

    /**
     * 启用禁用
     *
     * @param userId
     * @param status
     * @return
     */
    @PostMapping("/updateUserStatus")
    @ApiOperation(value = "启用禁用")
    public Object updateUserStatus(@ApiParam(value = "用户id") @RequestParam @NotNull Integer userId, @ApiParam(value = "0启用,1禁用") @RequestParam @NotNull Integer status) {
        return adminWxUserService.updateUserStatus(userId, status);
    }

}
